<?php
declare(strict_types=1);

namespace Zms\AdminHelper;

use Zms\Unit\Directory;
use Zms\Unit\Json;

class TheServer
{
    /**
     * 获取扩展安装版本信息
     * @return array
     */
    public function composerInfo(): array
    {
        $lock = Json::decode(file_get_contents(BASE_PATH . '/composer.lock'));
        $list = [];
        foreach ($lock['packages'] as $item) {
            $list[$item['name']] = $item['version'];
        }
        return $list;
    }


    /**
     * 获取日志目录大小
     * @return int
     */
    public function loggerSize(): int
    {
        $dir = BASE_PATH . '/runtime/logger';
        if (!is_dir($dir)) {
            return 0;
        }
        return Directory::getSize($dir);
    }
}